package com.eportal.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.log4j.Logger;


public class Config {

	private static Logger log = Logger.getLogger(Config.class);


	public static Map<String, String> accessTokenMap = new HashMap<String, String>(); 


	public static String MD_OPEN_ADD_AGENT;
	public static String MD_SEND_MSG;
	public static String MD_OPEN_ADD_COMMUNITY;
	public static String MD_OPEN_INSTALL_LOCK;
	public static String MD_OPEN_CHANGE_LOCK;
	public static String MD_OPEN_QRY_KEYS;
	public static String MD_OPEN_AGT_NUM;
	public static String MD_OPEN_APP_KEY;
	public static String MD_OPEN_TSHELVES_ADD;
	public static String MD_OPEN_TSHELVES_EDIT;
	public static String MD_OPEN_TSHELVES_URL;
	public static String MD_OPEN_TSTRATEGY_ADD;
	public static String MD_OPEN_TSTRATEGY_EDIT;
	public static String SYSTEMHIDE;
	public static String TAGENTHIDE;
	public static String TCOMMUNITYHIDE;
	public static String USERALBUMPIC;
	public static String MD_OPEN_WeChat;
	public static String LIFERESOURCEPATH;
	public static String LIFETEL;
	public static String ALIPAYAPPID;
	public static String ALIPAY_APP_PRIVATE_KEY;
	public static String ALIPAY_PUBLIC_KEY;
	public static String ALIPAYRETURNURL;
	
	public static String PAY_SERVICE_URL;
	

	static {
		try {
			loadConfig();
		} catch (Exception e) {
			log.error("", e);
			throw new RuntimeException("load weixin config error " + e.getMessage());
		}
	}
	
	public static String getpath(String name){
		if("lifeResource".equals(name)){
			return LIFERESOURCEPATH;
		}
		if("lifeTel".equals(name)){
			return LIFETEL;
		}
		return null;
	}
	
	private static void loadConfig() throws IOException{
		InputStream in = Config.class.getClassLoader()
				.getResourceAsStream("config.properties");
		Properties props = new Properties();
		props.load(in);
		MD_OPEN_ADD_AGENT = props.getProperty("MD_OPEN_ADD_AGENT", null);
		MD_SEND_MSG = props.getProperty("MD_SEND_MSG", null);
		MD_OPEN_ADD_COMMUNITY = props.getProperty("MD_OPEN_ADD_COMMUNITY", null);
		MD_OPEN_INSTALL_LOCK = props.getProperty("MD_OPEN_INSTALL_LOCK", null);
		MD_OPEN_CHANGE_LOCK = props.getProperty("MD_OPEN_CHANGE_LOCK", null);
		MD_OPEN_QRY_KEYS = props.getProperty("MD_OPEN_QRY_KEYS", null);
		MD_OPEN_AGT_NUM = props.getProperty("MD_OPEN_AGT_NUM", null);
		MD_OPEN_APP_KEY = props.getProperty("MD_OPEN_APP_KEY", null);
		MD_OPEN_TSHELVES_ADD = props.getProperty("MD_OPEN_TSHELVES_ADD", null);
		MD_OPEN_TSHELVES_EDIT = props.getProperty("MD_OPEN_TSHELVES_EDIT", null);
		MD_OPEN_TSHELVES_URL = props.getProperty("MD_OPEN_TSHELVES_URL", null);
		MD_OPEN_TSTRATEGY_ADD = props.getProperty("MD_OPEN_TSTRATEGY_ADD", null);
		MD_OPEN_TSTRATEGY_EDIT = props.getProperty("MD_OPEN_TSTRATEGY_EDIT", null);
		SYSTEMHIDE = props.getProperty("SYSTEMHIDE", null);
		TAGENTHIDE = props.getProperty("TAGENTHIDE", null);
		TCOMMUNITYHIDE = props.getProperty("TCOMMUNITYHIDE", null);
		USERALBUMPIC = props.getProperty("USERALBUMPIC", null);
		MD_OPEN_WeChat = props.getProperty("MD_OPEN_WeChat", null);
		LIFERESOURCEPATH = props.getProperty("LIFERESOURCEPATH", null);
		LIFETEL = props.getProperty("LIFETEL", null);
		ALIPAYAPPID = props.getProperty("ALIPAYAPPID", null);
		ALIPAYRETURNURL = props.getProperty("ALIPAYRETURNURL", null);
		ALIPAY_APP_PRIVATE_KEY = props.getProperty("ALIPAY_APP_PRIVATE_KEY", null);
		ALIPAY_PUBLIC_KEY = props.getProperty("ALIPAY_PUBLIC_KEY", null);
		PAY_SERVICE_URL = props.getProperty("PAY_SERVICE_URL",null);
	}
	
	
	public static void refreshConfig(){
		try {
			loadConfig();
		} catch (IOException e) {
			log.error("", e);
			throw new RuntimeException("load weixin config error " + e.getMessage());
		}
	}
	


}
